/*
 * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
 *
 * SPDX-License-Identifier: CC0-1.0
 */

#include <stdio.h>
#include <inttypes.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
#include "esp_system.h"

#include "led.h"
#include "spi.h"
#include "oled.h"
// #include "wifi_scan.h"

#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_mac.h"
#include "esp_log.h"
#include "esp_netif.h"
#include "nvs_flash.h"

#include "AppLayer.h"
#include "ButtonLayer.h"
#include "debug.h"
#include "config.h"
#include "esp_rtc.h"
#include "resources.h"
#include "draw.h"



// i2c_obj_t i2c0_master;

// static const char *TAG = "scan";
char* weekdays[]={"Sunday","Monday","Tuesday","Wednesday",
    "Thursday","Friday","Saterday"};



void app_main(void)
{
    uint8_t i_100ms = 0;
    uint8_t i_1s = 0;
    esp_err_t ret;
    char tbuf[40];

    ret = nvs_flash_init();             /* 初始化NVS */
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
    {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }

    printf("Hello world!\n");

    led_init();
    spi2_init();
    oled_init();

    /* Print chip information */
    chip_test();

    xm_button_init();
    xm_button_2_init();
    c_setup();
    rtc_set_time(2024,6,25,00,00,00);   /* 设置RTC时间 */

    draw_bitmap(46, 14, selectbar_top, 36, 8, 0, 0);
    // wifi_scan();
    
    while(1)
    {
        // LED_TOGGLE();
        // c_loop();
        if(i_100ms++ >= 10)
        {
            
            printf("Hello world!\n");
            i_100ms = 0;
        }

        if(i_1s++ >= 100)
        {
            i_1s = 0;

        }
        draw_bitmap(46, 14, menu_alarm, 32, 32, 0, 0);
        // rtc_get_time();
        // sprintf((char *)tbuf, "%02d:%02d:%02d", calendar.hour, calendar.min, calendar.sec);
        // printf("%s\n", tbuf);
        // dis_show_string(0, 0, 128, 64, tbuf, 12);
        oled_show_deal();
        vTaskDelay(100 / portTICK_PERIOD_MS);
    }

    fflush(stdout);

    // esp_restart();
}
